#include "config.h"

#include <QDir>
#include <QStandardPaths>

QString Config::configDir()
{
    QString path = QStandardPaths::writableLocation(QStandardPaths::ConfigLocation);
    return path + QDir::separator();
}

QString Config::appConfigDir()
{
    QString path = configDir() + "mediawiki-analyzer";
    QDir dir;
    dir.mkdir(path);
    return path + QDir::separator();
}

QString Config::appConfigFile(const QString &filename)
{
    QString path = appConfigDir() + filename;
    return path;
}

QString Config::getAppDataConfig()
{
    QFile file(appConfigFile("data.json"));
    file.open(QFile::ReadOnly);
    return file.readAll();
}

void Config::setAppDataConfig(const QString &dataPath)
{
    QFile file(appConfigFile("data.json"));
    file.open(QFile::WriteOnly);
    file.write(dataPath.toUtf8());
    file.flush();
}
